package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FunctionHelper;

public class ABS extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
      if (paramArrayOfObject[i] instanceof Number)
        return FunctionHelper.parsePrimitiveDouble(Math.abs(((Number)paramArrayOfObject[i]).doubleValue()));
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "ABS(number): 返回指定数字的绝对值。绝对值是指没有正负符号的数值。\nNumber:需要求出绝对值的任意实数。\n示例:\nABS(-1.5)等于1.5。\nABS(0)等于0。\nABS(2.5)等于2.5。";
  }

  public String getEN()
  {
    return "ABS(number): Returns the absolute value of a number. The absolute value of a number is the number without its sign.\nNumberNumber is the real number of which you want the absolute value.\nExample:\n   ABS(-1.5)=1.5\n   ABS(0)=0\n   ABS(2.5)=2.5";
  }
}